package com.ibiaoke.goods.dao;

import com.ibiaoke.common.base.BaseDao;
import com.ibiaoke.common.base.Page;
import com.ibiaoke.common.utils.StringUtils;
import com.ibiaoke.goods.entity.ReportLoss;
import com.ibiaoke.goods.entity.ReportLossExample;
import com.ibiaoke.goods.mapper.ReportLossMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;

@Repository
public class ReportLossDao extends BaseDao<ReportLoss, ReportLossExample, Integer, ReportLossMapper> {
    @Autowired
    private ReportLossMapper reportLossMapper;
    @Override
    public ReportLossMapper getMapper() {
        return reportLossMapper;
    }


    public List<ReportLoss> selectReportLoss(String goodName, Integer goodId, Date lossTime,
                                             Date lossEndtime,Integer shopId, Page page) {

        ReportLossExample example = new ReportLossExample();
        ReportLossExample.Criteria criteria = example.createCriteria();

        if (StringUtils.isNotEmpty(goodName)) {
            criteria.andGoodNameLike("%" + goodName + "%");
        }

        if (goodId != null) {
            criteria.andGoodIdEqualTo(goodId);
        }

        if (lossTime != null) {
            criteria.andLossTimeGreaterThanOrEqualTo(lossTime);
        }

        if(lossEndtime!=null){
            criteria.andLossTimeLessThanOrEqualTo(lossEndtime);
        }

        if (shopId != null) {
            criteria.andShopIdEqualTo(shopId);
        }

        page.setTotalCount(reportLossMapper.countByExample(example));
        example.setLimitStart(page.limitStart());
        example.setLimitEnd(page.limitEnd());
        example.setOrderByClause("create_time desc");
        return selectByExample(example);

    }
}
